/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.aal.business;

import com.aal.bean.EmployeeFacadeLocal;
import com.aal.bean.OrderProductFacade;
import com.aal.bean.ProductFacadeLocal;
import com.aal.bean.WarehouseFacadeLocal;
import com.aal.bean.WarehouseIOFacadeLocal;
import com.aal.entity.WarehouseIO;
import java.util.Date;
import javax.ejb.EJB;
import javax.ejb.Stateless;
/**
 *
 * @author quy
 */
@Stateless
public class WarehouseIOManagement implements WarehouseIOManagementLocal {
    @EJB
    private WarehouseFacadeLocal warehouseFacade;
    @EJB
    private EmployeeFacadeLocal employeeFacade;
    @EJB
    private OrderProductFacade ordersFacade;
    @EJB
    private ProductFacadeLocal productFacade;
    @EJB
    private WarehouseIOFacadeLocal warehouseIOFacade;
    
    @Override
    public boolean createWarehouseIO(int productID, int warehouseID, boolean type, int quantity, Date date, long orderID, String employeeID) {
        try{
            WarehouseIO warehouseIO = new WarehouseIO();
            warehouseIO.setIoid(Integer.MIN_VALUE);
            warehouseIO.setProductID(productFacade.find(productID));
            warehouseIO.setWarehouseID(warehouseFacade.find(warehouseID));
            warehouseIO.setType(type);
            warehouseIO.setQuantity(quantity);
            warehouseIO.setDate(date);
            warehouseIO.setOrderID(ordersFacade.find(orderID));
            warehouseIO.setEmployeeID(employeeFacade.find(employeeID));
            warehouseIOFacade.create(warehouseIO);
        }catch(Exception ex){
            return false;
        }
        return true;
    }
    public boolean editWarehouseIO(int IOID,int productID,int warehouseID,boolean type, int quantity, Date date, long orderID, String employeeID){
        try{
            WarehouseIO warehouseIO = warehouseIOFacade.find(IOID);
            warehouseIO.setIoid(Integer.MIN_VALUE);
            warehouseIO.setProductID(productFacade.find(productID));
            warehouseIO.setWarehouseID(warehouseFacade.find(warehouseID));
            warehouseIO.setType(type);
            warehouseIO.setQuantity(quantity);
            warehouseIO.setDate(date);
            warehouseIO.setOrderID(ordersFacade.find(orderID));
            warehouseIO.setEmployeeID(employeeFacade.find(employeeID));
            warehouseIOFacade.edit(warehouseIO);
        }
        catch(Exception ex){
            return false;
        }
        return true;
    }
    public boolean deleteWarehouseIO(int IOID){
        try
        {
            WarehouseIO warehouseIO = warehouseIOFacade.find(IOID);
            warehouseIOFacade.remove(warehouseIO);
        }catch(Exception ex){
            return false;
        }
        return true;
    }
}


